Skip to content

fix(studio): a sealed preview shows paused video frames from Studio's decoder - #8466

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/sealed-paused-frame
Nov 22, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/sealed-paused-frame

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

A paused video in a sealed Studio preview (VITE_STUDIO_OPAQUE_PREVIEW_ENABLED=1) now shows Studio's decoded frame, as it does unsealed. Before, the paused foreground showed the browser's own video element, because Studio's decoder was never installed in a frame it cannot script.

Why

attachPausedVideoProvider installed the decoder by calling the frame's window.__hf.setPausedVideoFrameProvider and read iframe.contentDocument. A sealed frame has an opaque origin, so both are out of reach and the function returned early (pausedVideoProvider.ts:15 on main). The preview-video-regression check fails sealed at its first paused step: "Paused foreground has no decoded canvas".

How

One path for both modes:

  • Studio opens a MessageChannel per frame load. It hands one end to the runtime with a new editing request, serve-paused-frames { channel }, sent with a transfer list (the editing client's request gains a transfer option).
  • The runtime's agent installs a port-backed provider through the existing setPausedVideoFrameProvider. Core's prepare and present code is unchanged.
  • Each paused decode is one ask on that port. The frame sends the source's path on its own server and only the media proxy's own options (hf-proxy, hf-proxy-box, hf-proxy-light, hf-proxy-retry), never a URL. Frame rate and VFR go along as timing hints.
  • Studio resolves every ask itself before reading anything:
    • The path must sit on this project's preview route (PREVIEW_PATH, the frame-token route included), with no ., .. or empty segment after decoding.
    • It must name a file in the project's file list from Studio's own server.
    • Studio then builds the URL on its own origin.
  • Why this gives the film nothing new: a sealed film can already load any project file through the preview route, which is how its own videos play. So a decoded frame of a project video gives it nothing it could not already read, and the file-list check keeps reads to exactly that set.
  • Caps per port:
    • at most PAUSED_FRAME_SOURCES (4, the decoder's reader budget) sources per decode;
    • one decode in flight, so a second is refused, not queued. An abort frees the slot only once the aborted decode settles;
    • at most PAUSED_FRAME_BYTES (128 MB, the runtime's own present budget) of frames per reply.
  • Frames cross the port as createImageBitmap copies, transferred. The decoder's cached frame is released at once.
  • Source facts now come in each ask from the runtime's own sourceFactsOfSrc, so the decoder no longer reads the frame's window. Its private suffix lookup is gone.
  • Old runtimes: a runtime without the request kind answers unknown-kind, and Studio closes the port. That preview keeps native frames, as sealed previews do today.

Test plan

  • fails without the fix: packages/studio/src/player/lib/pausedVideoProvider.sealed.test.ts ("a sealed frame's runtime decodes paused frames through Studio, which reads only the project file")

    • It runs on the real sealedPreviewFrame and drives resolveFramePlaybackAdapter.
    • With the base's source restored on the devbox, it fails: the runtime never gets a provider (expected "vi.fn()" to be called once, but got 0 times). With this branch, it passes 3 runs in a row.
  • pausedVideoProvider.test.ts: Studio refuses each of these without calling the decoder:

    • a URL the frame names, and a host-relative URL;
    • another project's file;
    • a path that climbs out, plain or percent-encoded;
    • a file the project does not have;
    • an ask carrying any option but the proxy's;
    • more than 4 sources in one decode;
    • a second decode while one runs, including after the first was aborted but has not yet settled;
    • frames over the byte budget (released, never copied).
  • packages/core/src/runtime/editing/pausedFrames.test.ts: an ask carries only the path and the proxy's options, never another server's media. An abort is told to Studio, and dispose rejects what is pending.

  • On the devbox, named tests 3 of 3 green; all 74 covering files green; tsc clean in core and studio; Fallow and pre-push clean.

  • preview-video-regression on the devbox, Studio dev server, 2 runs per mode:

    • Unsealed: passes 2 of 2.
    • Sealed: the paused steps now pass in both runs (decoded paused foreground, one-frame step, capture isolation, picking). Later steps fail in both runs, on main as well as here:
      • A slider-release seek lands after the script's own in-frame seek ("Seek to 7 did not publish", time 9.667). It failed the same way on main.
      • The delayed-native-recovery step fails: the frame navigated mid-step here, and native delivery was not held on main.
    • Main's sealed runs: made with the paused-canvas block cut, because main fails at the first paused step. Neither later step touches the paused decoder; both are tracked separately.
  • Cost: time from a paused one-frame seek to the decoded canvas showing that frame, 24 seeks per run, same fixture and same devbox, at this branch's base c731046c vs this branch:

    base median / p90 branch median / p90
    unsealed, run 1 74.0 / 97.0 ms 74.7 / 97.7 ms
    unsealed, run 2 69.7 / 101.4 ms 65.5 / 91.3 ms
    sealed, run 1 no decoded canvas 69.2 / 80.2 ms
    sealed, run 2 no decoded canvas 57.8 / 74.9 ms

    The unsealed bitmap copy is within run-to-run noise.

Before

Sealed preview at this branch's base, paused at 2.000 s on the preview-video-regression fixture: the browser's own video element draws the frame. The regression check then fails with "Paused foreground has no decoded canvas".

Before: sealed paused frame at 2.000 s, drawn by the browser's own video element

After

The same frame with this change: Studio's decoded canvas draws it, as unsealed. The pictures match at this frame. The difference is which surface draws it: the decoded canvas is frame-exact at full source detail, which the regression check's frame step and detail checks assert.

After: the same frame, drawn on Studio's decoded canvas

Related work

Refs #7846 (the sealed-by-default preview).

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 57 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes, for one blocker. I reviewed at 15550fc2.

Need ✅ · Size ✅ · Reuse ✅ (setPausedVideoFrameProvider, PREVIEW_PATH and the decoder are reused; the frame-window lookup is gone) · Simpler ✅ · Structure ⚠️ (the per-port cap)
Risk: medium. Studio now decodes on a frame's behalf.

What holds up:

  • Path checks. projectFileOf takes only this project's preview route. It rejects ., .. and empty segments after decoding, and turns away bad escapes.
  • File list. Every path is then looked up in the project's file list before anything is read.
  • Studio builds the address. The URL is assembled on Studio's own origin with encodeUrlPath.
  • Parameters. parsePausedFrameAsk keeps only the four proxy parameters, with PARAM_VALUE-checked values, plus finite hints.
  • Images. They cross the port as transferred ImageBitmap copies. The decoder's frame is released in finally.
  • Tests: studio pausedVideo* and playbackAdapterResolution pass 39/39. Core pausedFrames, editingAgent and editingPort pass 177/177. Studio tsc is clean, and CI is green.

Blocker: the "one decode in flight" cap doesn't hold after an abort.
pausedFrameHost deletes the id from inFlight the moment an abort arrives (port.onmessage, the abort branch). refusal() then sees an empty map and admits the next decode, while the aborted decoder.decode(...) is still running until it next checks its signal. The original call's finally no longer finds its entry, so nothing counts it.

Probe: a stub decoder whose decode never settles, then decode and abort five times on one port. decoder.decode was called 5 times, all running at once, where the body says "one decode in flight, so a second is refused, not queued". Each call can open up to PAUSED_FRAME_SOURCES readers, so the per-port limit is really unbounded.

Fix:

  • On abort, call control.abort() but keep the entry. Let the decode's own finally remove it once the call has actually ended.
  • Then a new ask will hit "busy" during a normal paused scrub. To keep that smooth, hold at most one waiting ask (newest wins, and it replaces an older waiting one) and start it when the slot frees, rather than refusing it.
  • Add a test with a decoder that settles only after its signal fires, asserting decode never runs twice at once.

— Rames (hf-review)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at d164050: approve.

My blocker from 15550fc is resolved. An abort message now only calls abort() on the controller. The one-decode slot is freed solely in decode's own finally, and inFlight.get(id) === control guards that delete. A second decode is therefore refused "Preview decoder busy" until the aborted one settles, and then it is served. close() still aborts and clears every slot, so a closed host cannot be held.

Red-first: verified. With pausedVideoProvider.ts at 15550fc, the new test "keeps an aborted decode's slot until that decode settles" fails (the second decode reaches the decoder). At head, pausedVideoProvider.test.ts and pausedVideoProvider.sealed.test.ts pass 11/11. Nothing else changed since 15550fc, which I reviewed in full.

Note, not blocking: a decoder that ignores its abort signal and never settles holds the slot until the host closes. That is the intended side for a one-at-a-time budget.

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ (the fix is a deletion) · Structure ✅
Risk: low.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 61008a4 Nov 22, 2026
167 of 178 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-paused-frame branch November 22, 2026 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants